﻿@using Abp.Collections.Extensions
@using MyCompanyName.AbpZeroTemplate.Web.Areas.AppAreaName.Views.Shared.Components.AppAreaNameMenu
@model UserMenuItemViewModel

<li class="kt-menu__item kt-menu__item--submenu @(Model.MenuItem.IsMenuActive(Model.CurrentPageName) ? "kt-menu__item--active" : "") @(Model.MenuItem.IsMenuActive(Model.CurrentPageName) && Model.MenuItem.Items.Count > 0 ? "kt-menu__item--open" : "")"
    aria-haspopup="true"
    @(Model.RootLevel ? "" : " role=none")
    data-ktmenu-submenu-toggle="hover">
    @if (Model.MenuItem.Items.IsNullOrEmpty())
    {
        if (string.IsNullOrEmpty(Model.MenuItem.Target))
        {
            Model.MenuItem.Target = "_self";
        }
        <a href="@Model.MenuItem.CalculateUrl(ApplicationPath)" class="kt-menu__link" target="@Model.MenuItem.Target"
           role="menuitem"
           aria-haspopup="true"
           aria-expanded="false"
           tabindex="@(Model.MenuItemIndex == 0 ? "0" : "-1")">
            <span class="kt-menu__item-here"></span>
            <span class="kt-menu__link-icon">
                <i class="kt-menu__link-icon @Model.MenuItem.Icon"></i>
            </span>
            <span class="kt-menu__link-text">
                @Model.MenuItem.DisplayName
            </span>
        </a>
    }
    else
    {
        <a href="#" class="kt-menu__link kt-menu__toggle"
           role="menuitem"
           aria-haspopup="true"
           aria-expanded="false"
           tabindex="@(Model.MenuItemIndex == 0 ? "0" : "-1")">
            <span class="kt-menu__item-here"></span>
            <span class="kt-menu__link-icon">
                <i class="kt-menu__link-icon @Model.MenuItem.Icon"></i>
            </span>
            <span class="kt-menu__link-text">
                @Model.MenuItem.DisplayName
            </span>
            <i class="kt-menu__ver-arrow la la-angle-right"></i>
        </a>
        <nav class="kt-menu__submenu" aria-label="@Model.MenuItem.DisplayName">
            <span class="kt-menu__arrow"></span>
            <ul class="kt-menu__subnav"
                role="menu"
                aria-label="@Model.MenuItem.DisplayName">
                @for (var i = 0; i < Model.MenuItem.Items.Count; i++)
                {
                    var childMenuItem = Model.MenuItem.Items[i];
                    if (!childMenuItem.IsVisible)
                    {
                        continue;
                    }
                    @await Html.PartialAsync("Components/AppAreaNameMenu/_UserMenuItem", new UserMenuItemViewModel
                       {
                           MenuItem = childMenuItem,
                           MenuItemIndex = i,
                           CurrentPageName = Model.CurrentPageName,
                           RootLevel = false
                       })
                }
            </ul>
        </nav>
    }
</li>
